package com.gss.armory.domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.hibernate.validator.constraints.NotBlank;




@Entity
@Table(name="COMPANY_DETAILS")
public class CompanyDetailsDTO implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 3921088620226526844L;

	private int cdId;
	
	@NotBlank
	private String cdName;
	
	@NotBlank
	private String cdCode;
	
	private String address;
	private String cdCity;
	private String cdDistrict;
	private String cdState;
	private boolean child;
	private String companyType;
	private Integer parentId;
	
	private CompanyDetailsDTO parentCompany;
	
	private List<BusinessUnitDetailsDTO> businessUnitList = new ArrayList<BusinessUnitDetailsDTO>();
	
	private List<LocationDetailsDTO> locationList = new ArrayList<LocationDetailsDTO>();
	
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column (name = "CD_ID")
	public int getCdId() {
		return cdId;
	}
	
	@Column(name="CD_NAME",length=151,nullable=false)
	public String getCdName() {
		return cdName;
	}
	
	@Column(name="CD_CODE",length=21,nullable=false)
	public String getCdCode(){
		return cdCode;
	}
	
	@Column(name="CD_CITY",length=30)
	public String getCdCity() {
		return cdCity;
	}

	@Column(name="CD_DISTRICT",length=30)
	public String getCdDistrict() {
		return cdDistrict;
	}

	@Column(name="CD_STATE",length=30)
	public String getCdState() {
		return cdState;
	}
	@Column(name="CD_ADDRESS",length=1500)
	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}
	
	public void setCdCity(String cdCity) {
		this.cdCity = cdCity;
	}

	public void setCdDistrict(String cdDistrict) {
		this.cdDistrict = cdDistrict;
	}

	public void setCdState(String cdState) {
		this.cdState = cdState;
	}
	
	
	@ManyToOne
	@JoinTable(name="DM_COMPANY_GROUPING"
		, joinColumns= @JoinColumn(name="LGM_CHILD_COMPANY_ID")
		, inverseJoinColumns = @JoinColumn(name="LGM_PARENT_COMPANY_ID"))
	public CompanyDetailsDTO getParentCompany() {
		return parentCompany;
	}
	
	@OneToMany(targetEntity=BusinessUnitDetailsDTO.class,mappedBy="buCompany")
	@LazyCollection(value=LazyCollectionOption.FALSE)
	public List<BusinessUnitDetailsDTO> getBusinessUnitList() {
		return businessUnitList;
	}
	
	@OneToMany(targetEntity=LocationDetailsDTO.class,mappedBy="ldCompanyId")
	@LazyCollection(value=LazyCollectionOption.FALSE)
	public List<LocationDetailsDTO> getLocationList() {
		return locationList;
	}
	
	@Column(name = "CD_IS_CHILD", nullable = false, columnDefinition = "smallint default 1")
	public boolean isChild() {
		return child;
	}

	public void setChild(boolean child) {
		this.child = child;
	}


	public void setLocationList(List<LocationDetailsDTO> locationList) {
		this.locationList = locationList;
	}
	
	public void setCdId(int cdId) {
		this.cdId = cdId;
	}
	public void setCdName(String cdName) {
		this.cdName = cdName;
	}
	public void setCdCode(String cdCode){
		this.cdCode = cdCode;
	}


	public void setParentCompany(CompanyDetailsDTO parentCompany) {
		this.parentCompany = parentCompany;
	}


	public void setBusinessUnitList(List<BusinessUnitDetailsDTO> businessUnitList) {
		this.businessUnitList = businessUnitList;
	}

	@Column(name="CD_COMPANY_TYPE")
	public String getCompanyType() {
		return companyType;
	}

	public void setCompanyType(String companyType) {
		this.companyType = companyType;
	}

	@Column(name="CD_PARENT_ID", nullable = true)
	public Integer getParentId() {
		return parentId;
	}

	public void setParentId(Integer parentId) {
		this.parentId = parentId;
	}
}
